package enums.table;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据库类型枚举
 */
public enum TableTypeEnum {
	INT ("int", "java.lang.Integer", "INTEGER", "Integer", ""),
	VARCHAR ("varchar", "java.lang.String", "VARCHAR", "String", ""),
	CHAR ("char", "java.lang.String", "VARCHAR", "String", ""),
	BLOB ("blob", "java.lang.Byte", "BYTE", "Byte[]", ""),
	INTEGER ("integer", "java.lang.Long", "LONG", "Long", ""),
	TINYINT ("tinyint", "java.lang.Integer", "INTEGER", "Integer", ""),
	SMALLINT ("smallint", "java.lang.Integer", "INTEGER", "Integer", ""),
	MEDIUMINT ("mediumint", "java.lang.Integer", "INTEGER", "Integer", ""),
	BIT ("bit", "java.lang.Boolean", "BOOLEAN", "Boolean", ""),
	BIGINT ("bigint", "java.math.BigInteger", "BIGINTEGER", "BigInteger", ""),
	FLOAT ("float", "java.lang.Float", "FLOAT", "Float", ""),
	DOUBLE ("double", "java.lang.Double", "DOUBLE", "Double", ""),
	DECIMAL ("decimal", "java.math.BigDecimal", "BIGDECIMAL", "BigDecimal", ""),
	PK ("pk", "java.lang.Long", "LONG", "Long", ""),
	DATE ("date", "java.lang.Date", "TIMESTAMP", "Date", ""),
	TIME ("time", "java.lang.Date", "TIMESTAMP", "Date", ""),
	DATETIME ("datetime", "java.lang.Date", "TIMESTAMP", "Date", ""),
	TIMESTAMP ("timestamp", "java.lang.Date", "TIMESTAMP", "Date", ""),
	YEAR ("year", "java.lang.Date", "TIMESTAMP", "Date", ""),
	TEXT ("text", "java.lang.String", "VARCHAR", "String", ""),
	;

	// 数据库中的类型
	private String dataType;
	// Java中的类型
	private String javaType;
	// 类名
	private String jdbcType;
	// 类名
	private String clazz;
	// 备注
	private String remark;

	public static void main(String args[]) {
		for (TableTypeEnum tableType : TableTypeEnum.values()) {
			System.out.println(tableType.toString().toUpperCase()
					+ " " + "(\"" + tableType.getDataType().toLowerCase() + "\","
					+ " " + "\"" + tableType.getJavaType() + "\","
					+ " " + "\"" + tableType.getRemark() + "\"),"
					);
		}
	}

	private TableTypeEnum(String dataType, String javaType, String jdbcType, String clazz, String remark) {
		this.dataType = dataType;
		this.javaType = javaType;
		this.jdbcType = jdbcType;
		this.clazz = clazz;
		this.remark = remark;
	}

	public String getDataType() {
		return dataType;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	public String getJavaType() {
		return javaType;
	}

	public void setJavaType(String javaType) {
		this.javaType = javaType;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getClazz() {
		return clazz;
	}

	public void setClazz(String clazz) {
		this.clazz = clazz;
	}

	public String getJdbcType() {
		return jdbcType;
	}

	public void setJdbcType(String jdbcType) {
		this.jdbcType = jdbcType;
	}

	/**
	 * 获取数据库类型枚举 List集合
	 */
	public static List<TableTypeEnum> getEnumList() {
		List<TableTypeEnum> list = new ArrayList<>();
		for (TableTypeEnum tableType : TableTypeEnum.values()) {
			list.add(tableType);
		}
		return list;
	}

	/**
	 * 根据 数据库字段类型 获取 Java类型
	 */
	public static TableTypeEnum getEnumByDataType(String dataType) {
		if (null == dataType) {
			return null;
		}
		for (TableTypeEnum tableType : TableTypeEnum.values()) {
			if (tableType.getDataType().equals(dataType)) {
				return tableType;
			}
		}
		return null;
	}

	/**
	 * 根据 Java类型 获取 数据库字段类型
	 */
	public static List<TableTypeEnum> getEnumByJavaType(String javaType) {
		if (null == javaType) {
			return null;
		}

		List<TableTypeEnum> list = new ArrayList<>();
		for (TableTypeEnum tableType : TableTypeEnum.values()) {
			if (tableType.getJavaType().equals(javaType)) {
				list.add(tableType);
			}
		}
		return list;
	}
}
